import 'dart:math';

import 'package:get/get.dart';
import 'package:ty_smart_watch/bean/health_detail_bean.dart';
import 'package:ty_smart_watch/utils/Log.dart';

class CommonController extends GetxController {
  //柱状图数据
  Rx<List<double>> dataList = Rx<List<double>>([]);
  List<double> dayList = [];
  List<double> weekList = [];
  List<double> monthList = [];

  //详细数据
  Rx<List<HealthDetailBean>> detailList = Rx<List<HealthDetailBean>>([]);

  Rx<int> dateTypeIndex = 0.obs;

  //最新值
  Rx<int> currentData = 0.obs;

  //最大值
  Rx<int> maxData = 0.obs;

  //最小值
  Rx<int> minData = 0.obs;

  initDayList() {
    _updateDataBarList([]);
    dayList.clear();
    for (int i = 0; i < 24; i++) {
      dayList.add(0);
    }
    _updateDataBarList(dayList);
  }

  initWeekList() {
    _updateDataBarList([]);
    weekList.clear();
    for (int i = 0; i < 7; i++) {
      weekList.add(0);
    }
    _updateDataBarList(weekList);
  }

  initMonthList() {
    _updateDataBarList([]);
    monthList.clear();
    // 获取当前日期时间
    DateTime now = DateTime.now();
    // 获取当月的天数
    int daysInMonth = DateTime(now.year, now.month + 1, 0).day;
    Log.d("days in month: $daysInMonth");
    for (int i = 0; i < daysInMonth; i++) {
      monthList.add(0);
    }
    _updateDataBarList(monthList);
  }

  ///获取 日 柱状数据
  getDayBarList() {
    _updateDataBarList([]);
    dayList.clear();
    //实际数据操作
    for (int i = 1; i <= 24; i++) {
      dayList.add(i * 3);
    }
    //实际数据操作
    _updateDataBarList(dayList);
  }

  ///获取 周 柱状数据
  getWeeBarkList() {
    _updateDataBarList([]);
    weekList.clear();
    //实际数据操作
    for (int i = 0; i < 7; i++) {
      weekList.add(i * 20);
    }
    //实际数据操作
    _updateDataBarList(weekList);
  }

  ///获取 月 柱状数据
  getMonthBarList() {
    _updateDataBarList([]);
    monthList.clear();
    //实际数据操作
    // 获取当前日期时间
    DateTime now = DateTime.now();
    // 获取当月的天数
    int daysInMonth = DateTime(now.year, now.month + 1, 0).day;
    for (int i = 0; i < daysInMonth; i++) {
      monthList.add(i * 5);
    }
    //实际数据操作
    _updateDataBarList(monthList);
  }

  /// 获取详细的数据
  getDayDetailList() {
    var tempList = <HealthDetailBean>[];
    for (int i = 0; i < Random().nextInt(50); i++) {
      tempList.add(HealthDetailBean(Random().nextInt(10000), Random().nextInt(200).toString()));
    }
    _updateDetailList(tempList);
  }

  /// 更新List
  _updateDataBarList(List<double> list) {
    dataList(list);
    dataList.refresh();
  }

  _updateDetailList(List<HealthDetailBean> list) {
    detailList(list);
    detailList.refresh();
  }
}
